/*
 * @Description: 开启缓存路由组件名称,  mate中设置
 * @Author: wangqi
 * @Date: 2022-04-21 14:42:54
 * @LastEditTime: 2022-04-21 14:57:41
 */

import { defineStore } from 'pinia';
interface KeepAliveState {
  list: string[];
}

export const useKeepAliveStore = defineStore('keep-alive', {
  state: (): KeepAliveState => ({
    list: [],
  }),
  getters: {},
  actions: {
    add(name: string | string[]) {
      if (typeof name === 'string') {
        !this.list.includes(name) && this.list.push(name);
      } else {
        name.map((val) => {
          val && !this.list.includes(val) && this.list.push(val);
        });
      }
    },
    remove(name: string | string[]) {
      if (typeof name === 'string') {
        this.list = this.list.filter((val) => name !== val);
      } else {
        this.list = this.list.filter((val) => !name.includes(val));
      }
    },
    clear() {
      this.list = [];
    },
  },
});
